package com.irdstudio.efp.riskm.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.riskm.service.dao.MonReliefAppDao;
import com.irdstudio.efp.riskm.service.domain.MonReliefApp;
import com.irdstudio.efp.riskm.service.facade.MonReliefAppService;
import com.irdstudio.efp.riskm.service.vo.MonReliefAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 息费减免申请 <p>
 * @author ligm
 * @date 2019-10-29
 */
@Service("monReliefAppService")
public class MonReliefAppServiceImpl implements MonReliefAppService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(MonReliefAppServiceImpl.class);

	@Autowired
	private MonReliefAppDao monReliefAppDao;
	
	/**
	 * 新增操作
	 */
	public int insertMonReliefApp(MonReliefAppVO inMonReliefAppVo) {
		logger.debug("当前新增数据为:"+ inMonReliefAppVo.toString());
		int num = 0;
		try {
			MonReliefApp monReliefApp = new MonReliefApp();
			beanCopy(inMonReliefAppVo, monReliefApp);
			num = monReliefAppDao.insertMonReliefApp(monReliefApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(MonReliefAppVO inMonReliefAppVo) {
		logger.debug("当前删除数据条件为:"+ inMonReliefAppVo);
		int num = 0;
		try {
			MonReliefApp monReliefApp = new MonReliefApp();
			beanCopy(inMonReliefAppVo, monReliefApp);
			num = monReliefAppDao.deleteByPk(monReliefApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inMonReliefAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(MonReliefAppVO inMonReliefAppVo) {
		logger.debug("当前修改数据为:"+ inMonReliefAppVo.toString());
		int num = 0;
		try {
			MonReliefApp monReliefApp = new MonReliefApp();
			beanCopy(inMonReliefAppVo, monReliefApp);
			num = monReliefAppDao.updateByPk(monReliefApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inMonReliefAppVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public MonReliefAppVO queryByPk(MonReliefAppVO inMonReliefAppVo) {
		
		logger.debug("当前查询参数信息为:"+ inMonReliefAppVo);
		try {
			MonReliefApp queryMonReliefApp = new MonReliefApp();
			beanCopy(inMonReliefAppVo, queryMonReliefApp);
			MonReliefApp queryRslMonReliefApp = monReliefAppDao.queryByPk(queryMonReliefApp);
			if (Objects.nonNull(queryRslMonReliefApp)) {
				MonReliefAppVO outMonReliefAppVo = beanCopy(queryRslMonReliefApp, new MonReliefAppVO());
				logger.debug("当前查询结果为:"+ outMonReliefAppVo.toString());
				return outMonReliefAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<MonReliefAppVO> queryAllOwner(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefAppVO> list = null;
		try {
			List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllOwnerByPage(monReliefAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ monReliefApps.size());
			pageSet(monReliefApps, monReliefAppVo);
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<MonReliefAppVO> queryAllCurrOrg(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询本人所属机构数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrOrgByPage(monReliefAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			pageSet(monReliefApps, monReliefAppVo);
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<MonReliefAppVO> queryAllCurrDownOrg(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrDownOrgByPage(monReliefAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			pageSet(monReliefApps, monReliefAppVo);
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllCurrOwnerPrd(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询产品类型下数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrOwnerPrdByPage(monReliefAppVo);
		logger.debug("当前查询产品类型下数据信息的结果集数量为:"+ monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			pageSet(monReliefApps, monReliefAppVo);
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllByConditions(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefAppVO> list = new ArrayList<>();
		try {
			List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllByConditions(monReliefAppVo);
			logger.debug("当前查询的结果集数量为:"+ monReliefApps.size());
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllDetail(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前查询息费减免明细的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefAppVO> list = new ArrayList<>();
		try {
			List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllDetailByPage(monReliefAppVo);
			logger.debug("当前查询息费减免明细的结果集数量为:"+ monReliefApps.size());
			pageSet(monReliefApps, monReliefAppVo);
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllDetailExp(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前导出息费减免明细的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefAppVO> list = new ArrayList<>();
		try {
			List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllDetailExp(monReliefAppVo);
			logger.debug("当前导出息费减免明细的结果集数量为:"+ monReliefApps.size());
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllOwnerExp(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前导出本人所属数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefAppVO> list = null;
		try {
			List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllOwnerExp(monReliefAppVo);
			logger.debug("当前导出本人所属数据信息的结果集数量为:"+ monReliefApps.size());
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllCurrOrgExp(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前导出本人所属机构数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrOrgExp(monReliefAppVo);
		logger.debug("当前导出本人所属机构数据信息的结果集数量为:"+monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllCurrDownOrgExp(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前导出本人所属机构及以下数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrDownOrgExp(monReliefAppVo);
		logger.debug("当前导出本人所属机构及以下数据信息的结果集数量为:"+ monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<MonReliefAppVO> queryAllCurrOwnerPrdExp(MonReliefAppVO monReliefAppVo) {
		logger.debug("当前导出产品类型下数据信息的参数信息为:" +monReliefAppVo.toString());
		List<MonReliefApp> monReliefApps = monReliefAppDao.queryAllCurrOwnerPrdExp(monReliefAppVo);
		logger.debug("当前导出产品类型下数据信息的结果集数量为:"+ monReliefApps.size());
		List<MonReliefAppVO> list = null;
		try {
			list = (List<MonReliefAppVO>) beansCopy(monReliefApps, MonReliefAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

}
